

#include <TFile.h>
#include <iostream>
#include <string>
#include <TTree.h>
#include <TH1D.h>
#include <TF1.h>
#include <TCanvas.h>
using namespace std;
string filePath = "../RootData/";
void CheckRawData(string fileName = "ToF_Sort_Coin_20251126_8")
{
    TCanvas *c1 = new TCanvas();
    // TFile *file = new TFile("../RootData/ToF_Sort_Coin_ToFdata_0916.root", "read");
    TFile *file = new TFile((filePath + fileName + ".root").c_str(), "read");
    TTree *treeAna_ToF = new TTree();
    // file->GetObject("treeCoin_ToF", treeAna_ToF);
    file->GetObject("treeCoin_ToF", treeAna_ToF);
    double ToF;

    //TF1* f1 = new TF1("f1", "gaus", -0.7, 0);
      TH1D *hTOF = new TH1D("hToF", "hToF", 1000, -2, 2);
    // treeAna_ToF->Draw("tmDif_Tstart[0][1]>>hToF", "", "colz");
    // treeAna_ToF->Draw("tmDif[1][3]>>hToF", "", "colz");
       treeAna_ToF->Draw("tsFine_ToF[2]>>hTOF(200, 0, 200)");
      //  treeAna_ToF->Draw("tmDif_Tstart[0][2]>>hTOF(200, -0.5, -0.2)");
    // gStyle->SetOptStat(111111);
    // treeAna_ToF->Draw("tmDif_Tstart[1][3]>>hTOF(100,-0.8,-0.4)","","colz");
    // treeAna_ToF->Draw("tmDif_Tstart[0][2]:tmDif_Tstart[1][3]>>hTOF(1000, -1, -0.4,1000,1.6,2)","","colz");
    // ->GetXaxis()->SetTitle("ToF_{1,3}");
    // treeAna_ToF->GetYaxis()->SetTitle("ToF_{0,2}");
    // TH2F*hTOF = (TH2F*)gPad->GetPrimitive("hTOF");
    // TH1F*hTOF = (TH1F*)gPad->GetPrimitive("hTOF");
    // TH1F*hTOF = (TH2F*)gPad->GetPrimitive("hTOF");
    // hTOF->GetXaxis()->SetTitle("ToF_{1-3}(ns)");
    // hTOF->GetXaxis()->SetTitle("ToF_{0-2}(ns)");
    // hTOF->GetYaxis()->SetTitle("Counts");
    // treeAna_ToF->Draw("tmDif[1][3]>>hTOF", "", "colz");
    // hTOF->Fit(f1, "R");
    // gStyle->SetOptFit(111111);
    // gStyle->SetStat(111111);
    // hTOF->GetXaxis()->SetTitle("ToF(0-2)(ns)");
    // hTOF->GetYaxis()->SetTitle("ToF(1-3)(ns)");
    // hTOF->Draw();
    // treeAna_ToF->Draw("tmDif[1][0]-tmDif[0][0]>>hTOF(10000, -2, 2)", "", "colz");
    // c1->GetXaxis()->SetTitle("ToF(1-0)(ns)");
    // c1->GetYaxis()->SetTitle("ToF(1-3)(ns)");
    // c1->Draw();
    c1->SetTitle(fileName.c_str());
    gPad->Update();
    c1->WaitPrimitive();
}
int main(int argc, char const *argv[])
{
    CheckRawData();
    return 0;
}
